#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年9月18日

@author: chenyongbing
'''
import sys,os,logging
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]

'''
    验证接口数据是否正确
'''

sys.path.append(os.path.join(current_dir,'../../'))

from base.apiRequest import myApiRequest
#from base.zhimind_datas import myZhimindDatas


class zhimindForBGYAPI():
    '''
        碧桂园接口验证
    '''
    def __init__(self,baseUrl='',token='',startTime=None,endTime=None,comp_group=''):
        self.baseUrl = baseUrl
        self.token = token
        self.startTime = startTime
        self.endTime = endTime
        self.comp_group = comp_group
    
    def search_customers(self,hasMobile=0,searchKey='',minCount=-1,maxCount=-1,orderItem=2,orderType=2,currentPage=1,pageNumber=10):
        '''
            顾客信息查询
            URL：xxx/zm-ws-3.0/api/v3/realty/search_customers Method：HTTP Post
            
            校验Token     Token     String    固定值：10002000
            公司groupId     CompGroup     int    
            最近来访开始时间     StartTime     String    yyyy-MM-dd
            最近来访结束时间     EndTime     String    yyyy-MM-dd
            是否关联手机     HasMobile     int    取值: 0:所有 1:关联用户
            手机/MAC搜索关键字     SearchKey     String     注备：大小写不敏感
            累计来访最小值     MinCount     int    
            累计来访最大值     MaxCount     int    
            排序字段     OrderItem     int    1：按首次接触时间；2：最近到访时间；3：累计来访
            排序类型     OrderType     int    0：正序；1：逆序
            请求第几页     CurrentPage     int    默认为：1
            每页显示条数     PageNumber     int    默认为：10
        '''
        url = self.baseUrl+'/realty/search_customers'
        
        paramap={'StartTime':self.startTime,'EndTime':self.endTime,'CompGroup':self.comp_group,
                 'HasMobile':hasMobile,'SearchKey':searchKey,
                 'MinCount':minCount,'MaxCount':maxCount,
                 'OrderItem':orderItem,'OrderType':orderType,
                 'CurrentPage':currentPage,'PageNumber':pageNumber,
                 'Token':self.token}
        
        retStr=myApiRequest.getResponse(url, paramap)
        return retStr
    
    
    def customer_details(self,mac=''):
        '''
            顾客详情
            URL：xxx/zm-ws-3.0/api/v3/realty/customer_details Method：HTTP Post
            编码：UTF-8
            Content-Type: application/x-www-form-urlencoded
            
            接口参数：
            
            名称     参数名     类型     说明
            校验Token     Token     String    固定值：10002000
            公司groupId     CompGroup     int    
            MAC地址     Mac     String    格式:a1b2c3d4e5f6
        '''
        url = self.baseUrl+'/realty/customer_details'
        
        paramap={'CompGroup':self.comp_group,
                 'Mac':mac,
                 'Token':self.token}
        
        retStr=myApiRequest.getResponse(url, paramap)
        return retStr
        
if __name__=='__main__':
    logging.basicConfig(level = logging.INFO)
    baseUrl = 'http://183.131.78.213:8180/zm-ws-3.0/api/v3'
    token = '10002000'
    startTime = '2015-09-21'
    endTime = '2015-09-21' 
    comp_group = 32010222
    myZhimindForBGYAPI = zhimindForBGYAPI(baseUrl = baseUrl , token = token,startTime = startTime , endTime = endTime ,comp_group =comp_group)
    minCount = 2
    maxCount = 2
#     for orderItem in [0,1,2]:
#         for orderType in [0,1]:
#             
    orderItem = 0 
    orderType = 0
    print myZhimindForBGYAPI.search_customers(hasMobile=1,currentPage=1,orderItem=orderItem,orderType = orderType,minCount=minCount,maxCount = maxCount)
    print myZhimindForBGYAPI.customer_details(mac='18593688cf21')

class zhimindApiCheck():
    def __init__(self):
        pass
    